//
//  NetworkErrorView.m
//  Dispatch
//
//  Created by hyeyeon on 14. 2. 26..
//  Copyright (c) 2014년 hyeyeon. All rights reserved.
//

#import "NetworkErrorView.h"

@implementation NetworkErrorView
@synthesize delegate, tag, networkURL;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self makeView:frame];
    }
    return self;
}

-(void)makeView:(CGRect)frame{
    
    self.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.8f];

    
    UIImageView *logo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 50, 150, 41)];
    logo.image = [UIImage imageNamed:@"dispatch_logo"];
    logo.center = CGPointMake(frame.size.width*0.5f, logo.center.y);
    [self addSubview:logo];
    
    UILabel *netLabel = [[UILabel alloc]initWithFrame:CGRectZero];
    netLabel.text = @"현재 네트워크에 연결되어 있지 않습니다.";  //영어 텍스트 필요
    [netLabel sizeToFit];
    netLabel.center = CGPointMake(frame.size.width*0.5f, logo.frame.origin.y+logo.frame.size.height+(netLabel.frame.size.height*0.5f)+15);
    netLabel.textColor = ColorFromRGB(0xffffff);
    netLabel.font = [UIFont boldSystemFontOfSize:15];
    [self addSubview:netLabel];
    
    UILabel *subLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    subLabel.text = @"나중에 다시 시도하세요";
    [subLabel sizeToFit];
    subLabel.center = CGPointMake(frame.size.width*0.5f, netLabel.frame.origin.y+netLabel.frame.size.height+(subLabel.frame.size.height*0.5f)+12);
    subLabel.textColor = ColorFromRGB(0xffffff);
    subLabel.font = [UIFont boldSystemFontOfSize:14];
    [self addSubview:subLabel];
    
    UIButton *reloadButton = [[UIButton alloc] initWithFrame:CGRectMake(0, subLabel.frame.origin.y+subLabel.frame.size.height+47, 150, 38)];
    [reloadButton setBackgroundImage:[UIImage imageNamed:@"btn_blue"] forState:UIControlStateNormal];
    [reloadButton addTarget:self action:@selector(reloadButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    NSString *string = languagesKorean ? @"다시 시도" : @"Reload";
    [reloadButton setTitle:string forState:UIControlStateNormal];
    [reloadButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:reloadButton];
    
    reloadButton.center = CGPointMake(frame.size.width*0.5f, reloadButton.center.y);
    
    
}

-(void)reloadButtonAction:(id)sender{
    
    if ([delegate respondsToSelector:@selector(networkErrorViewReloadClick:andURLstr:)]) {
        [delegate networkErrorViewReloadClick:self andURLstr:self.networkURL];
    }
    [self removeReloadView];
}

-(void)removeReloadView{
    if ([self superview]) {
        [self removeFromSuperview];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
